package cn.wolfcode.trip.admin.controller;
import cn.wolfcode.trip.base.domain.Hotel;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.HotelQueryObject;
import cn.wolfcode.trip.base.service.IHotelService;
import cn.wolfcode.trip.base.util.JsonResult;
import cn.wolfcode.trip.base.util.UploadUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@Controller
@RequestMapping("/hotel")
public class HotelController {
    @Autowired
    private IHotelService hotelService;
    /**
     * 酒店列表
     * @param qo
     * @return
     */
    @RequestMapping("/list")
    public String getList(@ModelAttribute("qo") HotelQueryObject qo, Model model){
        PageInfo pageInfo = hotelService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "hotel/list";
    }

    /**
     * 增加或者修改
     * @param hotel
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Hotel hotel,MultipartFile img) {
        //先判断后台是否更新了照片
        if (img != null && img.getContentType().startsWith("image")&&img.getSize()>0){
            String imgUrl = UploadUtil.upload(img);
            hotel.setRoomUrl(imgUrl);
        }
        hotelService.saveOrUpdate(hotel);
        return "redirect:/hotel/list.do";
    }
   @RequestMapping("/delete")
    public Object delete(Long id){
       hotelService.delete(id);
        return new JsonResult();
   }

    /**
     * 获取该酒店对象id下的对应的详情内容
     * @param id
     * @return
     */
   @RequestMapping("/getContent")
   @ResponseBody
    public Object getContent(Long id){
       return hotelService.getContent(id);
   }
}
